package com.thirteenClassics.async;

import com.thirteenClassics.dto.EntryCatalogQueryDTO;
import com.thirteenClassics.dto.EntryDTO;
import com.thirteenClassics.vo.EntryCatalogQueryVO;
import com.thirteenClassicsServer.common.EntryCommonService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class EntryServiceAsync {
    @Autowired
    private EntryCommonService commonService;

    @Async
    @CachePut(value = "EntryCache", key = "'Entry-' + #entryCatalogQueryDTO.bookId + '-' + #entryCatalogQueryDTO"
            + ".bookName + '-' + #entryCatalogQueryDTO.index + '-' + #entryCatalogQueryDTO.sentenceIndex + '-' + "
            + "#entryCatalogQueryDTO.paragraphIndex")
    public EntryCatalogQueryVO selectCatalogAndAllFlashCache(EntryCatalogQueryDTO entryCatalogQueryDTO) {
        return commonService.selectCatalogAndAllCommon(entryCatalogQueryDTO);
    }

    @Async
    @CachePut(value = "EntryCacheNew", key = "'EntryNew-' + #entryCatalogQueryDTO.bookId + '-' + #entryCatalogQueryDTO"
            + ".bookName + '-' + #entryCatalogQueryDTO.index + '-' + #entryCatalogQueryDTO.sentenceIndex + '-' + "
            + "#entryCatalogQueryDTO.paragraphIndex")
    public EntryCatalogQueryVO selectCatalogAndAllFlashCacheNew(EntryCatalogQueryDTO entryCatalogQueryDTO) {
        return commonService.selectCatalogAndAllCommonNew(entryCatalogQueryDTO);
    }

    @CacheEvict(value = "EntryCache", key = "'Entry-' + #entryDto.bookId + '-' + #entryDto.bookName + '-' + #entryDto"
            + ".index + '-' + #entryDto.sentenceIndex + '-' + #entryDto.paragraphIndex")
    public void evictEntryCache(EntryDTO entryDto) {
    }

    @CacheEvict(value = "EntryCacheNew", key = "'EntryNew-' + #entryDto.bookId + '-' + #entryDto.bookName + '-' + #entryDto"
            + ".index + '-' + #entryDto.sentenceIndex + '-' + #entryDto.paragraphIndex")
    public void evictEntryCacheNew(EntryDTO entryDto) {
    }

}
